﻿Ext.extend(NExt.data.RpcProxy, Ext.data.DataProxy, {
    doRequest: function(action, rs, params, reader, cb, scope, arg) {
        this.requestContext = {
            action: action,
            rs: rs,
            params: params,
            reader: reader,
            cb: cb,
            scope: scope,
            arg: arg
        };

        var callback = {
            scope: this,
            success: this.callbackSuccess,
            failure: this.callbackFailure
        };

        this.theDelegate.call(scope, params.query, params.start, params.limit, callback);
    },

    callbackSuccess: function(records) {
        var rc = this.requestContext;
        var result = rc.reader.readRecords(records);
        rc.cb.call(rc.scope, result, rc.arg, result.success);
    },

    callbackFailure: function(response, options) {
        var rc = this.requestContext;
        rc.cb.call(rc.scope, null, rc.arg, false);
    }
});